package org.hs.phd.odi.tracking.performanceevaluation;

import java.awt.Polygon;

import org.hs.phd.common.simpleplayer.ImageSequenceFrame;

public abstract class AbstractTrackingPerformanceMetric implements TrackingPerformanceMetric {
	
	private float lastValue;
	private float averageValue;
	private int numberOfMeasurements;
	
	public AbstractTrackingPerformanceMetric(){
		lastValue = 0;
		averageValue = 0;
		numberOfMeasurements = 0;
	}

	@Override
	public void update(ImageSequenceFrame frame, Polygon groundTruthTrackShape, Polygon computedTrackShape) {
		lastValue = compute(frame, groundTruthTrackShape, computedTrackShape);
		numberOfMeasurements++;
		averageValue += (lastValue - averageValue)/numberOfMeasurements;
		
	}

	@Override
	public float getLastValue() {
		return lastValue;
	}

	@Override
	public float getAverageValue() {
		return averageValue;
	}

	protected abstract float compute(ImageSequenceFrame frame, Polygon groundTruthTrackShape, Polygon computedTrackShape);

	@Override
	public TrackingPerformanceMetric clone() {
		try {
			return (TrackingPerformanceMetric) super.clone();
		} catch (CloneNotSupportedException e) {
			throw new Error(e);
		}
	}
}
